package com.heima.admin.controller.v1;

import com.heima.admin.service.SensitiveService;
import com.heima.api.admin.SensitiveControllerApi;
import com.heima.model.admin.dtos.SensitiveDto;
import com.heima.model.admin.pojos.AdSensitive;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName SensitiveController
 * @Description TODO
 * @Author AWei
 * @DATE 2021/4/10 19:25
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/v1/sensitive")
public class SensitiveController implements SensitiveControllerApi {

    @Resource
    SensitiveService sensitiveService;

    /**
     * @param dto 分页数据以及敏感词名称 对象
     * @return 分页查询结果
     * @Description 查询敏感词列表
     */
    @Override
    @PostMapping("/list")
    public ResponseResult querySensitiveByPageOrName(@RequestBody SensitiveDto dto) {
        return sensitiveService.querySensitiveByPageOrName(dto);
    }

    /**
     * @param adSensitive 新增的敏感词对象
     * @return 新增结果
     * @Description 新增敏感词
     */
    @Override
    @PostMapping("/save")
    public ResponseResult addSensitive(@RequestBody AdSensitive adSensitive) {
        return sensitiveService.addSensitive(adSensitive);
    }

    /**
     * @param adSensitive 修改的敏感词对象
     * @return 修改结果
     * @Description 修改
     */
    @Override
    @PostMapping("/update")
    public ResponseResult modifySensitive(@RequestBody AdSensitive adSensitive) {
        return sensitiveService.modifySensitive(adSensitive);
    }

    /**
     * @param id 删除对象id
     * @return 删出结果
     * @Description 删除
     */
    @Override
    @DeleteMapping("/del/{id}")
    public ResponseResult deleteSensitive(@PathVariable("id") Integer id) {
        return sensitiveService.deleteSensitive(id);
    }
}
